<?php
/**
 * 关闭action Csrf
 *
 * PHP version 5
 *
 * @package   YuDian
 * @author    Fee <Fee@shorigo.com>
 * @copyright 2016 Shangyuanruige Inc.
 */
namespace app\components;

use yii\base\ActionEvent;
use yii\base\Behavior;
use yii\web\Controller;

class NoCsrfBehavior extends Behavior
{
    public $actions = [];
    
    public $controller;
    
    public function events()
    {
        return [Controller::EVENT_BEFORE_ACTION => 'beforeAction'];
    }
    
    public function beforeAction($event)
    {
        $action = $event->action->id;
        if(in_array($action, $this->actions)){
            $this->controller->enableCsrfValidation = false;
        }
    }    
}
?>